public class Example12_4 {
   public static void main(String args[ ]) {
      House house = new House();
      house.setWater(10);
      house.dog.start();
      house.cat.start();
   }
}
 class House implements Runnable {
   int waterAmount;
   Thread dog,cat;
   House() {
      dog=new Thread(this);
      cat=new Thread(this);
   }
   public void setWater(int w) {
      waterAmount = w;
   }
   public void run() {
      while(true) {
         Thread t=Thread.currentThread();
         if(t==dog) {
            System.out.println("�ҹ���ˮ") ;
            waterAmount=waterAmount-2;
         }
         else if(t==cat){
            System.out.println("��è��ˮ") ;
            waterAmount=waterAmount-1;
         }
         System.out.println(" ʣ "+waterAmount);
         try{  Thread.sleep(2000);
         }
         catch(InterruptedException e){}
         if(waterAmount<=0) {
            return;
         }
      }
   }
}
